package org.geek4j.repository;

import org.geek4j.solr.model.Item;
import org.geek4j.solr.repository.ItemRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.solr.core.query.result.HighlightEntry;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author Geek4J
 * 
 * @Description Tester 4 Item repository
 */

@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-solr.xml")
public class ItemRepositoryT {

	@Autowired
	private ItemRepository itemRepository;

	/**
	 * @author Geek4J
	 * 
	 * @Description Tester 4 Item findByName
	 * 
	 */
	@Test
	public void findByName() {
		HighlightPage<Item> items = itemRepository.findByName("{key words}", new PageRequest(0, 10));
		for (HighlightEntry<Item> item : items.getHighlighted()) {
			log.error(item.getHighlights().get(0).getSnipplets().get(0));
			log.error(item.getHighlights().get(0).getSnipplets().get(1));
		}
	}

	@Test
	public void findByNameStartsWith() {
		Iterable<Item> items = itemRepository.findByNameStartsWith("{key words}", new PageRequest(0, 10));
		for (Item item : items) {
			log.error(item.getName());
		}
	}
}